<template>
  <MarkdownEdit :blog="blog" @save="saveBlog" @cancel="cancelBlog" />
  <FloatingButtons />
</template>

<script setup>
import { AddBlog } from "@/apis/allAPI/blog"
import FloatingButtons from "@/components/FloatingButtons.vue"
import MarkdownEdit from "@/components/MarkdownEdit.vue"
import appStore from "@/stores"
import { getCurTime } from "@/utils/time"
import { storeToRefs } from "pinia"
import { ref } from "vue"
import { useRouter } from "vue-router"

const blog = ref({
  author: 1,
  title: "",
  context: "",
  toc: [],
  desc: "",
  created_at: getCurTime(),
  updated_at: "",
  blog_cover: "",
  labels: [],
})
const router = useRouter()
const { isBlogLoading } = storeToRefs(appStore.homeviewStore)
const cancelBlog = () => {
  isBlogLoading.value = false
  router.push("/home")
}
const saveBlog = () => {
  blog.value.updated_at = getCurTime()
  AddBlog(blog.value, cancelBlog, () => {
    isBlogLoading.value = false
  })
}
</script>
